<?php
//session_start();
include_once 'inc/connect.php';
include 'inc/functies.php';

$titel = $_POST['titel'];
$locatie = $_POST['locatie'];
$omschrijving = $_POST['omschrijving'];
$startdatum = $_POST['date_start'];
$einddatum = $_POST['date_end'];
$starttijd = $_POST['time_start'];
$eindtijd = $_POST['time_end'];
$bavo = (isset($_POST['bavo']) ? $_POST['bavo'] : 0);
$inge = (isset($_POST['inge']) ? $_POST['inge'] : 0);
$berekening = $_POST['berekening'];
$gastenlijst = $_POST['gastenlijst'];

//echo $titel.'<br>'.$startdatum.'<br>'.$starttijd.'<br>Bavo: '.$bavo.'<br>Inge: '.$inge;
$startstring = reverseDate($startdatum).'T'.date('H:i:s',strtotime($starttijd)).'.000+01:00';
$eindstring = reverseDate($einddatum).'T'.date('H:i:s',strtotime($eindtijd)).'.000+01:00';
//echo $startstring.'<br>'.$eindstring;


$event = new Google_Event();
$event->setSummary($titel);
$event->setLocation($locatie);
$event->setDescription($omschrijving);
$start = new Google_EventDateTime();
//$start->setDateTime('2014-10-31T10:00:00.000+01:00');
/*$objDateTime = new DateTime($startstring);
$isoDate = $objDateTime->format(DateTime::ISO8601);*/

$start->setDateTime($startstring);
$event->setStart($start);
$eind = new Google_EventDateTime();
//$end->setDateTime('2014-10-31T10:25:00.000+01:00');
/*$objDateTime = new DateTime($eindstring);
$isoDate = $objDateTime->format(DateTime::ISO8601);*/

$eind->setDateTime($eindstring);
$event->setEnd($eind);
/*$attendee1 = new Google_EventAttendee();
$attendee1->setEmail('bavo.mannekens@gmail.com');
$attendees = array($attendee1);
$event->attendees = $attendees;*/
$cal = $_SESSION['cal'];
//$createdEvent = $cal->events->insert('wim.hambrouck@gmail.com', $event); //Returns array not an object
$createdEvent = $cal->events->insert('jossekorm@gmail.com', $event);

print_r($createdEvent);
?>